package com.cheng.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cheng.dao.system.UserDao;
import com.cheng.domain.system.Role;
import com.cheng.domain.system.User;
import com.cheng.service.system.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userDao;

	@Override
	public User findByUserName(String username) {
		return userDao.findByUsername(username);
	}

	@Override
	public List<User> findAllUser() {
		return userDao.findAll();
	}

	@Override
	public void saveUser(User model, Integer[] roleIds) {
		if (roleIds != null) {
			Role role = null;
			for (Integer rid : roleIds) {
				role = new Role();
				role.setId(rid);
				model.getRoles().add(role);
			}
		}
		userDao.save(model);
	}

	

}
